'use strict';

const APM = require('elastic-apm-node');
const apm = APM.start({
    serviceName: process.env.APM_SERVER_NAME,
    serverUrl: process.env.APM_SERVER_URL,
    metricsInterval: process.env.APM_METRICS || "0s", // 默认关闭metrics的搜集
    environment: process.env.NODE_ENV || 'development',
});

const { name: eggName, version: eggVersion } = require('egg/package.json');
apm.setFramework({ name: eggName, version: eggVersion });
// 过滤HEAD请求的记录（很多都是负载均衡器的存活检测）
apm.addFilter((payload) => {
    const method = payload.context && payload.context.request && payload.context.request.method;
    return method === 'HEAD' ? false : payload;
});

module.exports = apm;